package com.javasm.mb_store_api_final.giftsandgoods.gift.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.error.ExceptionEnum;
import com.javasm.error.JavasmException;
import com.javasm.mb_store_api_final.giftsandgoods.gift.dao.GmGift2GoodsDao;
import com.javasm.mb_store_api_final.giftsandgoods.gift.entity.GmGift2Goods;
import com.javasm.mb_store_api_final.giftsandgoods.gift.service.GmGift2GoodsService;
import com.javasm.mb_store_api_final.giftsandgoods.gift.vo.Gifts2GoodsVo;
import com.javasm.mb_store_api_final.giftsandgoods.goods.entity.GgGoods;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 赠品管理-赠品转商品(GmGift2Goods)表服务实现类
 *
 * @author makejava
 * @since 2024-08-01 11:25:47
 */
@Service("gmGift2GoodsService")
public class GmGift2GoodsServiceImpl extends ServiceImpl<GmGift2GoodsDao, GmGift2Goods> implements GmGift2GoodsService {
    @Resource
    GmGift2GoodsDao gmGift2GoodsDao;
    @Override
    public List<Gifts2GoodsVo> listGifts2GoodsVo(Gifts2GoodsVo g2gVo) {
        List<Gifts2GoodsVo> list = gmGift2GoodsDao.listGifts2GoodsVo(g2gVo);
        return list;
    }

    @Override
    public long getTatol() {
        long count =gmGift2GoodsDao.getTatol();
        return count;
    }

    @Override
    public List<String> listgtype() {
        List<String> types = gmGift2GoodsDao.listgtype();
        return types;
    }

    @Override
    public GmGift2Goods selectById(Integer id) {
        GmGift2Goods gmGift2Goods =gmGift2GoodsDao.getById(id);
        return gmGift2Goods;
    }

    @Override
    public boolean updateById1(GmGift2Goods gift2Goods) {
        Integer i=gmGift2GoodsDao.updateById1(gift2Goods);
        if (i==1){
            return true;
        }else {
            throw new JavasmException(ExceptionEnum.UpdateError);
        }

    }

    @Override
    public boolean delById(Integer id) {
        Integer i =gmGift2GoodsDao.delById(id);
        if (i==1){
            return false;
        }else {
            throw new JavasmException(ExceptionEnum.DeleteError);
        }

    }

    @Override
    public boolean saveGift2Goods(GmGift2Goods g2g) {
        g2g.setApplyStatus("未通过");
        g2g.setApplyUser("admin");
        boolean save = gmGift2GoodsDao.save(g2g);
        if (save){
            return true;
        }
        return false;
    }

    @Override
    public GgGoods getDetailById(Integer id) {
        GgGoods ggGoods = gmGift2GoodsDao.getDetailById(id);
        return ggGoods;
    }

    @Override
    public boolean updateGiftNum(Integer id, Integer count) {
        if (gmGift2GoodsDao.updateGiftNum(id,count)){
            return true;
        }
        return false;
    }
}

